<?php

  $filename = $config['logdir'].'/'.date('Y-m-d').'.sq3'; //separate DB for each day

  try {
    $db = new SQLite3($filename, SQLITE3_OPEN_READONLY);
    $sth = $dbh->prepare('select rowid, action, eventtype, time, measure from log where (action, eventtype, session, remoteid, user, time, value) values (:action, :eventtype, :session, :id, :user, :time, :value)');
    $dbh->beginTransaction();
    for($i = 0; $i<$cnt; $i++) {
      $sth->execute($data[$i]);
    }
    $dbh->commit();
    exit($data[$cnt-1]['id']);
  } catch (PDOException $e) {
    echo 'Connection to DB failed: ' . $e->getMessage();
  }
  
  $db->close();
?>